<?xml version="1.0" encoding="utf-8"?>
<include>
    <extension name="callback_{$task.id}">
        <condition field="destination_number" expression="^({$task.id})$">
            <action application="curl" data="http://127.0.0.1:8888/api/FSCallback/setTaskJobState?jobid=${JOBID}&callstate=success&failreason=_undef_"/>
            <action application="log" data="WARNING JOBID: ${JOBID}"/>
            <action application="set" data="effective_caller_id_name=TASK${TASKID}"/>
            <action application="set" data="sip_h_X-Gateway=${gateway}"/>
            <action application="set" data="hangup_after_bridge=false"/>
            <action application="set" data="continue_on_fail=true"/>
            {if ($task.callback_type == 'ivr') OR ($task.callback_type == 'ivr_transfer')}
            <action application="curl" data="http://127.0.0.1:8888/api/FSCallback/setTaskJobState?jobid=${JOBID}&ivrstate=started"/>
            <action application="playback" data="/usr/share/nginx/html/public{$sound.file}"/>
            <action application="curl" data="http://127.0.0.1:8888/api/FSCallback/setTaskJobState?jobid=${JOBID}&ivrstate=finished"/>
            {/if}
            {if ($task.callback_type == 'ivr')}
            <action application="start_dtmf"/>
            <action application="play_and_get_digits" data="1 1 1 10000 # /usr/share/nginx/html/fs_tpl/press_0.wav silence_stream://250 res 0" />
            <action application="log" data="WARNING play_and_get_digits-res: ${res}, -res_invalid: "${res_invalid}/>
            <action application="flush_dtmf"/>
            <action application="set" data="goqueue=${cond(${res} == 0 ? continue : hangup)}"/>
            <action application="set" data="goqueue=${cond(${goqueue} == continue ? continue : hangup)}"/>
            <action application="log" data="WARNING play_and_get_digits-goqueue: ${goqueue}"/>
            <action application="execute_extension" data="${goqueue} XML callback"/>
            {/if}
            {if ($task.callback_type == 'ivr') OR ($task.callback_type == 'transfer') OR ($task.callback_type == 'ivr_transfer')}
            <action application="curl" data="http://127.0.0.1:8888/api/FSCallback/setTaskJobState?jobid=${JOBID}&queuestate=queued"/>
            <action application="set" data="origination_nested_vars=true"/>
            <action application="set" data="prefix_dollar=\$"/>
            <action application="set" data="execute_on_answer=curl http://127.0.0.1:8888/api/FSCallback/setTaskJobState?jobid=${JOBID}&queuestate=recepted&receptionextension=${prefix_dollar}{cc_agent}"/>
            <action application="set" data="execute_on_post_bridge=curl http://127.0.0.1:8888/api/FSCallback/setTaskJobState?jobid=${JOBID}"/>
            <action application="set" data="sip_auto_answer=true"/>
            <action application="set" data="cc_export_vars=gateway,sip_h_X-Gateway,origination_nested_vars,execute_on_answer,sip_auto_answer"/>
            <!--<action application="set" data="bridge_pre_execute_aleg_app=set"/>
            <action application="set" data="bridge_pre_execute_aleg_data=export_vars=cc_agent"/>-->
            <!--<action application="set" data="bridge_pre_execute_bleg_data=WARNING test-gongji-test: test::\\$\\{effective_caller_id_number\\}"/>-->
            <!--<action application="verbose_events" data="true"/>-->
            <action application="export" data="speech_script_path={$speech_script_path}"/>
            <action application="export" data="speech_script_output_path={$speech_script_output_path}"/>
            <action application="curl" data="http://127.0.0.1:8888/api/FSCallback/setTaskJobState?jobid=${JOBID}&queuestate=recepted&receptionextension=AIScript-{$task.speech_id}"/>
            <action application="transfer" data="AIScript-{$task.speech_id} XML default"/>
            <action application="hangup" />
            <!--<action application="callcenter" data="TASK{$task.id}@callback_queue"/>-->
            <!--<action application="curl" data="http://127.0.0.1:8888/api/FSCallback/setTaskJobState?jobid=${JOBID}&queuestate=recepted&receptionextension=${cc_agent}"/>-->
            <!--action application="bridge" data="{originate_timeout=5}user/1001"/-->
            <!--<action application="log" data="WARNING gongji-outcall-222bridge hangup cause: ${bridge_hangup_cause}"/>
            <action application="log" data="WARNING gongji-ttt: ${cc_agent}"/>-->
            <!--<action application="info" data="outcall-222hangup cause: ${hangup_cause}"/>-->
            {/if}
        </condition>
    </extension>
</include>
